#include <include/AT91SAM7S64.h>
#include <include/defines.h>

#ifndef __TWI__
#define __TWI__
	
	#define TWI_IO 0x18;							//IO 3 en 4 worden gebruikt voor TWI
	
	//verwijzingen naar AT91SAM7S64 registers
  extern AT91PS_TWI p_pTWI;					//Creeer pointer naar TWI base address
  extern AT91PS_PMC p_pPMC;					//Creeer pointer naar Power Management Controller
  extern AT91PS_PIO p_pPIO;         //Creeer pointer naar Peripheral IO Controller
  
  //PIO Pull Up Disable Register
  #define PA3    0x00000004;        //TWD
  #define PA4    0x00000010;        //TWCK
  
  //TWI_CR TWI Control Register
  #define START  0x00000001;        //START puls.	
  #define STOP   0x00000002;        //STOP puls.
  #define MSEN   0x00000004;        //TWI Master Transfer Enabled
  #define MSDIS  0x00000008;        //TWI Master Transfer Disabled
  #define SWRST  0x00000080;        //Software Reset (1 = system reset)
  
  //TWI Master Mode Register
  #define IADRSZ 0x00000000;        //Internal Device Address Size (no internal device address)
  #define MREAD  0x00000000;        //Master write Direction
  
  //TWI Internal Address Register
  #define IADR   0x00000000;        //Internal Address
  
  //TWI Interrupt Enable Register  
  #define TXCOMP_INTR  0x00000001;                  
  #define RXRDY_INTR   0x00000002;                  
  #define TXRDY_INTR   0x00000004;                  
  #define NACK_INTR    0x00000100;                  
  
  void TWI_Init(void);
  void TWI_Write(unsigned int data);
  void TWI_Reset(void);
  int TWI_Read(void);
  void TWI_Start(unsigned int adress,unsigned int RNW);
  void TWI_Start1(unsigned char adress,unsigned char RNW,unsigned char *adresses,unsigned char amount);
  void TWI_Repeated_Start(void);
  void TWI_Stop(void);

#endif
